import { CreateTaskDto } from './dto/create.task.dto';
import { ObjectType } from './../../../types/obj-type';
import { TasksService } from '@src/service/admin/task/task.service';
import { Controller, Post, HttpCode, HttpStatus, Body, Get, Param, Delete, Patch, Query, ParseIntPipe, HttpException, Req } from '@nestjs/common';
import adminConfig from '@src/config/admin.config';
import { ApiOperation, ApiCreatedResponse, ApiOkResponse, ApiTags, ApiBearerAuth } from '@nestjs/swagger';
import { TaskRep } from './dto';
import { WebSocketGateway } from '@nestjs/websockets';

@ApiTags('api-task')
@ApiBearerAuth()
@Controller(`${adminConfig.adminPath}/task`)
export class TaskController {
  constructor(
    private readonly taskService: TasksService,
  ) { }
  /** 
     * 获取定时任务列表
    */
  @Get('list')
  @ApiOkResponse({ type: [TaskRep] })
  @HttpCode(HttpStatus.OK)
  public async getTaskList(@Query() queryOption: ObjectType): Promise<TaskRep[]> {
    return await this.taskService.findPage(queryOption);
  }


  /** 
   * 创建定时任务
  */
  @ApiOperation({ summary: '创建定时任务', description: '创建定时任务' })
  @ApiCreatedResponse({
    type: CreateTaskDto,
    description: '创建定时任务',
  })
  @ApiOkResponse({ type: [TaskRep] })
  @Post('create')
  @HttpCode(HttpStatus.CREATED)
  public async createTask(@Body() createTaskDto: CreateTaskDto): Promise<TaskRep[]> {
    const task = await this.taskService.create(createTaskDto);
    const result = await this.taskService.save(task);
    return result
  }

  /** 
   * 启动定时任务
  */
  @ApiOperation({ summary: '启动定时任务', description: '启动定时任务' })
  @Post('start')
  @HttpCode(HttpStatus.OK)
  public async startTask(@Body() bodyOptions: ObjectType): Promise<any> {
    return await this.taskService.startTask(bodyOptions);
  }
  /** 
   * 暂停定时任务
  */
  @ApiOperation({ summary: '暂停定时任务', description: '暂停定时任务' })
  @Post('stop')
  @HttpCode(HttpStatus.OK)
  public async stopTask(@Body() bodyOptions: ObjectType): Promise<any> {
    return await this.taskService.stopTask(bodyOptions);
  }
  /** 
   * 清除定时任务
  */


}